//document.write("<script type='text/javascript' src='"+baseUrl+"/js/easyui/jquery.easyui.min.js'");

function getprojectNameuri()
{
	return baseUrl;
}

var innerCallback;
var ck;
function openWinW2(URL,winName,winWidth,winHeight,isMax,isMin,callbackMethod){
	innerCallback=callbackMethod;
	if(winName == null) {
		winName = "";
	}
	if(!isMin) {
		isMin = false;
	}
	if($("#win_div_"+winName).size() > 0) {
		$("#win_div_"+winName).window('close');
		$("#win_iframe_"+winName).remove();
		$("#win_div_"+winName).remove();
	}
	var boardDiv = "<div id=\"win_div_"+winName+"\" class=\"easyui-window\" title=\"My Window\" style=\"width:"+winWidth+";height:"+winHeight+";padding:0px;background: #fafafa;overflow:hidden;\">" +
			"<\/div>";
	$(document.body).append(boardDiv);
	var boardIframe = "<iframe id=\"win_iframe_"+winName+"\" src=\""+URL+"\" frameborder=\"no\" border=\"0\" marginwidth=\"0\" marginheight=\"0\" style=\"width:100%;height:100%\"></iframe>";
	$("#win_div_"+winName).html(boardIframe);
	$("#win_div_"+winName).window({title:winName,shadow: true, modal: true,maximizable:isMax,minimizable:isMin,onResize:function(){
		if($("#win_iframe_"+winName).contents().find(".datagrid-f").length > 0)
		{
			$("#win_iframe_"+winName)[0].contentWindow.openwinresize();
		}
		
	},onClose:function(){
        $("#win_iframe_"+winName).remove();
        $("#win_div_"+winName).remove();
    }});
	//$("#win_iframe_"+winName,window.parent.document).attr("src", URL);
}
function openWinW(URL,winName,winWidth,winHeight,isMax,isMin)
{
	if(top.openWinW2==undefined)
		openWinW2(URL,winName,winWidth,winHeight,isMax,isMin,null);
	else
		top.openWinW2(URL,winName,winWidth,winHeight,isMax,isMin,null);
}
function openWinCallback(URL,winName,winWidth,winHeight,isMax,isMin,callbackMethod)
{
	top.openWinW2(URL,winName,winWidth,winHeight,isMax,isMin,callbackMethod);
}
function reloadRightframeDatagrid(tt)
{
	parent.rightFrame.$('#'+tt).datagrid("reload");
}
function closeWin(winName){
	var len= arguments.length;
	if(innerCallback!=null)
	{
		if(len==1){

		}else if(len==2){
			innerCallback.call(this,arguments[0],arguments[1]);
		}else if(len==3){
			innerCallback.call(this,arguments[0],arguments[1],arguments[2]);
		}else if(len==4){
			innerCallback.call(this,arguments[0],arguments[1],arguments[2],arguments[3]);
		}
	}
	if(winName == null) {
		winName = "";
	}
	$("#win_div_"+winName).window('close');
	$("#win_iframe_"+winName).remove();
	$("#win_div_"+winName).remove();
	innerCallback=null;
}



$(function() {
	$(".hy-usertree").each(function() {
		$(this).usertree();
	});
	$(".hy-userlayer").each(function() {
		$(this).userlayer();
	});
	$(".hy-menutree").each(function(i){
		$(this).menutree();
	});
	$(".hy-menunav").each(function() {
		$(this).menunav();
	});
	$(".hy-pagemenu").each(function() {
		$(this).pagemenu();
	});
	$(".hy-pagemenu2").each(function() {
		$(this).pagemenu2();
	});
	$(".hy-echarts").each(function() {
		$(this).echarts();
	});
	$(".hy-cutscreen").each(function() {
		$(this).cutscreen();
	});
	$(".hy-searchselect").each(function() {
		$(this).searchselect();
	});

	$(".hy-customtree").each(function() {
		$(this).customtree();
	});
	$(".hy-print").each(function() {
		$(this).print();
	});

	$(".hy-richtext").each(function() {
		$(this).richtext();
	});
	$(".hy-orgtree").each(function() {
		$(this).orgtree();
	});
	$(".hy-radio").each(function() {
		$(this).radio();
	});
	$(".hy-checkbox").each(function() {
		$(this).checkbox();
	});
	$(".hy-wordviewer").each(function() {
		$(this).wordviewer();
	});
	$(function($){
		
		$(".hy-codeselect").each(function() {
			$(this).codeselect();
		});
	})
	$(".hy-photoupload").each(function() {
		$(this).photoupload();
	});
	$(".hy-attupload").each(function() {
		$(this).attupload();
	});
	$(".hy-searchinput").each(function() {
		$(this).searchinput();
	});

	$(".hy-qrcode").each(function(){
		$(this).qrcode();
	});
	$(".hy-exportword").each(function(){
		$(this).exportword();
	});
	$(".hy-exportpdf").each(function(){
		$(this).exportpdf();
	});
	$(".hy-checkcode").each(function(){
		$(this).checkcode();
	});
	$(".hy-departselwin").each(function(){
		$(this).departselwin();
	});
	$(".hy-h5imgcompress").each(function(){
		$(this).h5imgcompress();
	});
	$(".hy-swfimgcompress").each(function(){
		$(this).swfimgcompress();
	});
});

(function($) {
	/**
	 * 用户树
	 * methodName 方法名或构造函数的options
	 * arg 方法传参
	 */
	$.fn.usertree = function(methodName,arg) {
		if (typeof methodName == "string") {
			var methodObj = $.fn.usertree.methods[methodName];
			if (methodObj) {
				return methodObj(this, arg);
			} else {
				return this.hybase(methodName, arg);
			}
			return;
		}

		methodName = methodName || {};
		return this.each(function() {
			var cData = $.data(this, "usertree");
			var defaults = {
				departtype:"2",
				multiselect:"0",
				checkedvalue:"",
				rootid:"",
				isreadonly:"0"
			}
			var opts;
			if (cData) {
				opts = $.extend(cData.options, methodName);
				cData.options = opts;
			} else {
				opts = $.extend(
					{},defaults,
					$.fn.usertree.parseOptions(this), methodName);
			}

			usertreeload(this,opts);
		});

		function usertreeload(obj,opt){
			var isinput=$(obj).is("input");
			if(isinput){
				var url=baseUrl+'user/easyuiusertree.xhtml?rootid='+opt.rootid+'&departtype='+opt.departtype+'&checked='+opt.checkedvalue;
				$(obj).combotree({
					url:url
				});
			}else{
				var url=baseUrl+'user/usertree.xhtml?rootid='+opt.rootid+'&departtype='+opt.departtype+'&checked='+opt.checkedvalue;
				var onclick = opt.onnodeclick;
				$.ajax({
					type:'get',
					url:url,
					dataType:"text",
					success:function(msg)
					{
						var setting = {};
						setting.check={enable:opt.multiselect=='1'};
						var cb;
						if(onclick!=undefined){
							if (typeof onclick == "string") {
								cb={onClick:function(event, treeId, treeNode, clickFlag){
									eval(onclick+'(event, treeId, treeNode, clickFlag)');
								}};
								setting.callback=cb;
							}else{
								var func = new Function();
								func = eval(onclick);
								cb={onClick:function(event, treeId, treeNode, clickFlag){
									func(event, treeId, treeNode, clickFlag);
								}};
								setting.callback=cb;
							}
						}

						var zNodes=eval('('+msg+')');
						$.fn.zTree.init($(obj), setting, zNodes);
					},
					error:function(msg){
					}
				});
			}
		}
	}
	$.fn.usertree.methods = {
		options : function(jq) {
			return $.data(jq[0], "usertree").options;
		},
		getValue:function(jq){
			if($(jq).is("input")){
				return $(jq).combotree('getValue');
			}else{
				var treeObj = $.fn.zTree.getZTreeObj($(jq).attr('id'));
				var nodes = treeObj.getCheckedNodes(true);
				var result=',';
				for(var i=0; i<nodes.length; i++){
					result += nodes[i].id+",";
				}
				return result;
			}
		},
		getText:function(jq){
			if($(jq).is("input")){
				return $(jq).combotree('getText');
			}else{
				var treeObj = $.fn.zTree.getZTreeObj($(jq).attr('id'));
				var nodes = treeObj.getCheckedNodes(true);
				var result=',';
				for(var i=0; i<nodes.length; i++){
					result += nodes[i].name+",";
				}
				return result;
			}
		}
	};

	$.fn.usertree.parseOptions=function(obj){
		var t=$(obj);
		return $.extend({},$.parser.parseOptions(obj,["rootid","multiselect","onnodeclick","departtype","checkedvalue"]),{});
	};

	/**
	 * 用户层
	 * methodName 方法名或构造函数的options
	 * arg 方法传参
	 */
	$.fn.userlayer = function(methodName,arg) {
		if (typeof methodName == "string") {
			var methodObj = $.fn.userlayer.methods[methodName];
			if (methodObj) {
				return methodObj(this, arg);
			} else {
				return this.hybase(methodName, arg);
			}
			return;
		}

		methodName = methodName || {};
		return this.each(function() {
			var cData = $.data(this, "userlayer");
			var opts;
			if (cData) {
				opts = $.extend(cData.options, methodName);
				cData.options = opts;
			} else {
				opts = $.extend(
					{},
					$.fn.userlayer.parseOptions(this), methodName);
			}

			userlayerload(this,opts);
		});

		function userlayerload(obj,options){
			$(obj).textbox('textbox').attr('readonly',true);
			var thisid=$(obj).attr('id');
			var submitcode=$(obj).attr('submitcode');
			var nextobj=$(obj).next();
			$(obj).before('<p id="'+thisid+'_p" class="select-data"></p>')

			$('#'+thisid+'_p').append($(obj));
			$('#'+thisid+'_p').append($(nextobj));

			var tbox=$(($(nextobj[0]).find('.textbox-text'))[0]);
			var app='<img id="'+thisid+'_img" class="select-img" src="'+baseUrl+'images/select-data.png"></img><input id="'+thisid+'_hidden" type="hidden"/>';
			if(submitcode!=undefined){
				app+='<input id="'+thisid+'_submit" name="'+submitcode+'" type="hidden"/>';
			}
			tbox.after(app);

			$('#'+thisid+'_img').on('click',function(){
				openWinCallback(baseUrl+'user/gotoSelectList.xhtml', '选择用户', '1000px', '550px', true, false
					,function setValue(title,x){
						var ids='';
						var names='';
						for(var key in x)
						{
							if(ids!=''){
								ids+=',';
								names+=',';
							}
							ids+=key;
							names+=x[key].user_name;
						}

						$(obj).textbox('setValue',names);
						$('#'+thisid+'_hidden').val(ids);
                        if(submitcode!=undefined){
                            $('#'+thisid+'_submit').val(ids);
                        }
					});
			});
		}
	}
	$.fn.userlayer.methods = {
		options : function(jq) {
			return $.data(jq[0], "userlayer").options;
		},
		getText:function(jq){
			return $(jq).textbox('getValue');
		},getValue:function(jq){
			var thisid=$(jq).attr('id');
			return $('#'+thisid+'_hidden').val();
		}
	};
	$.fn.userlayer.parseOptions=function(obj){
		var t=$(obj);
		return $.extend({},$.fn.panel.parseOptions(obj),$.parser.parseOptions(obj,[]),{});
	};
})(jQuery);
(function($) {
	/**
	 * 一级菜单导航
	 * methodName 方法名或构造函数的options
	 * arg 方法传参
	 */
	$.fn.menunav = function(methodName,arg) {
		if (typeof methodName == "string") {
			var methodObj = $.fn.menunav.methods[methodName];
			if (methodObj) {
				return methodObj(this, arg);
			} else {
				return this.hybase(methodName, arg);
			}
			return;
		}

		methodName = methodName || {};
		return this.each(function() {
			var cData = $.data(this, "menunav");
			var opts;
			if (cData) {
				opts = $.extend(cData.options, methodName);
				cData.options = opts;
			} else {
				opts = $.extend(
					{},
					$.fn.menunav.parseOptions(this), methodName);
			}

			menunavload(this,opts);
		});

		function menunavload(obj,options){
			//具体实现代码
			$(obj).empty();
			var activemenuid=options['activemenuid'];
			if(options['homeurl']){
				var active='';
				if(activemenuid=='home'){
					active=' class="active"';
				}
				var li='<li '+active+'><a href='+options['homeurl']+'>首页</a></li>'
				$(obj).append(li);
			}
			if(options['menuurl']){
				$.ajax({
					type:'get',
					url:baseUrl+'/index/menunav.xhtml',
					dataType:"text",
					success:function(msg)
					{
						var data=eval('('+msg+')');
						for(var i = 0; i < data.length; i++){
							var code = data[i].code;
							var name = data[i].name;
							var active='';
							if(code==activemenuid){
								active=' class="active"';
							}

							var li='<li'+active+'><a href="'+options['menuurl']+'?menuId='+code+'">'+name+'</a></li>'
							$(obj).append(li);
						}
					},
					error:function(msg){
					}
				});
			}
		}
	}
	$.fn.menunav.methods = {
		options : function(jq) {
			return $.data(jq[0], "menunav").options;
		}
	};

	$.fn.menunav.parseOptions=function(obj){
		var t=$(obj);
		return $.extend({},$.fn.panel.parseOptions(obj),$.parser.parseOptions(obj,["homeurl","menuurl"]),{});
	};

	/**
	 * 页面内菜单导航
	 * methodName 方法名或构造函数的options
	 * arg 方法传参
	 */
	$.fn.pagemenu = function(methodName,arg) {
		if (typeof methodName == "string") {
			var methodObj = $.fn.pagemenu.methods[methodName];
			if (methodObj) {
				return methodObj(this, arg);
			} else {
				return this.hybase(methodName, arg);
			}
			return;
		}

		methodName = methodName || {};
		return this.each(function() {
			var cData = $.data(this, "pagemenu");
			var opts;
			if (cData) {
				opts = $.extend(cData.options, methodName);
				cData.options = opts;
			} else {
				opts = $.extend(
					{},
					$.fn.pagemenu.parseOptions(this), methodName);
			}

			pagemenuload(this,opts);
		});

		function pagemenuload(obj,options){
			//具体实现代码
			var url=baseUrl+'index/pagemenu.xhtml';
			$.ajax({
				type:'post',
				url:url,
				dataType:"text",
				success:function(msg)
				{
					$(obj).append(msg);
					_initLeftMenu();
				},
				error:function(msg){
				}
			});
		}
	}
	$.fn.pagemenu.methods = {
		options : function(jq) {
			return $.data(jq[0], "pagemenu").options;
		}
	};

	$.fn.pagemenu.parseOptions=function(obj){
		var t=$(obj);
		return $.extend({},$.fn.panel.parseOptions(obj),$.parser.parseOptions(obj,[]),{});
	};
	/**
	 * 页面内菜单导航
	 * methodName 方法名或构造函数的options
	 * arg 方法传参
	 */
	$.fn.pagemenu2 = function(methodName,arg) {
		if (typeof methodName == "string") {
			var methodObj = $.fn.pagemenu2.methods[methodName];
			if (methodObj) {
				return methodObj(this, arg);
			} else {
				return this.hybase(methodName, arg);
			}
			return;
		}

		methodName = methodName || {};
		return this.each(function() {
			var cData = $.data(this, "pagemenu2");
			var opts;
			if (cData) {
				opts = $.extend(cData.options, methodName);
				cData.options = opts;
			} else {
				opts = $.extend(
					{},
					$.fn.pagemenu2.parseOptions(this), methodName);
			}

			pagemenu2load(this,opts);
		});

		function pagemenu2load(obj,options){
			//具体实现代码
			var url=baseUrl+'index/pagemenu2.xhtml';
			$.ajax({
				type:'post',
				url:url,
				dataType:"text",
				success:function(msg)
				{
					$(obj).append(msg);
					_initLeftMenu();
				},
				error:function(msg){
				}
			});
		}
	}
	$.fn.pagemenu2.methods = {
		options : function(jq) {
			return $.data(jq[0], "pagemenu2").options;
		}
	};

	$.fn.pagemenu2.parseOptions=function(obj){
		var t=$(obj);
		return $.extend({},$.fn.panel.parseOptions(obj),$.parser.parseOptions(obj,[]),{});
	};
	/**
	 * echarts组件
	 * methodName 方法名或构造函数的options
	 * arg 方法传参
	 */
	$.fn.echarts = function(methodName,arg) {
		if (typeof methodName == "string") {
			var methodObj = $.fn.echarts.methods[methodName];
			if (methodObj) {
				return methodObj(this, arg);
			} else {
				return this.hybase(methodName, arg);
			}
			return;
		}

		methodName = methodName || {};
		return this.each(function() {
			var cData = $.data(this, "echarts");
			var opts;
			if (cData) {
				opts = $.extend(cData.options, methodName);
				cData.options = opts;
			} else {
				opts = $.extend(
					{},
					$.fn.echarts.parseOptions(this), methodName);
			}

			echartsload(this,opts);
		});

		function echartsload(obj,options){
			//具体实现代码
			$.ajax({
				type:'get',
				url:baseUrl+'/echarts/getEcartsDataByCode.xhtml?code='+options.code,
				dataType:"text",
				success:function(msg)
				{
					var dom = $(obj)[0];
					var myChart = echarts.init(dom);

					var option=eval('('+msg+')');
					myChart.setOption(option);
				},
				error:function(msg){
				}
			});
		}
	}
	$.fn.echarts.methods = {
		options : function(jq) {
			return $.data(jq[0], "echarts").options;
		}
	};

	$.fn.echarts.parseOptions=function(obj){
		var t=$(obj);
		return $.extend({},$.fn.panel.parseOptions(obj),$.parser.parseOptions(obj,['code']),{});
	};

	/**
	 * 页面内菜单导航
	 * methodName 方法名或构造函数的options
	 * arg 方法传参
	 */
	$.fn.cutscreen = function(methodName,arg) {
		if (typeof methodName == "string") {
			var methodObj = $.fn.cutscreen.methods[methodName];
			if (methodObj) {
				return methodObj(this, arg);
			} else {
				return this.hybase(methodName, arg);
			}
			return;
		}

		methodName = methodName || {};
		return this.each(function() {
			var cData = $.data(this, "cutscreen");
			var opts;
			if (cData) {
				opts = $.extend(cData.options, methodName);
				cData.options = opts;
			} else {
				opts = $.extend(
					{},
					$.fn.cutscreen.parseOptions(this), methodName);
			}

			cutscreenload(this,opts);
		});

		function cutscreenload(obj,options){
			captureInit();

			$(obj).on("click",function(e){
				setTimeout(StartCapture,500);
			});
		}
	}
	$.fn.cutscreen.methods = {
		options : function(jq) {
			return $.data(jq[0], "cutscreen").options;
		}
	};

	$.fn.cutscreen.parseOptions=function(obj){
		var t=$(obj);
		return $.extend({},$.fn.panel.parseOptions(obj),$.parser.parseOptions(obj,[]),{});
	};

	/**
	 * methodName 方法名或构造函数的options
	 * arg 方法传参
	 */
	$.fn.searchselect = function(methodName,arg) {
		var defaults = {
			sourcetype:"codetable",
			codetable:"",
			parentobjid:""
		}
		if (typeof methodName == "string") {
			var methodObj = $.fn.searchselect.methods[methodName];
			if (methodObj) {
				return methodObj(this, arg);
			} else {
				return this.hybase(methodName, arg);
			}
			return;
		}

		methodName = methodName || {};
		return this.each(function() {
			var cData = $.data(this, "searchselect");
			var opts;
			if (cData) {
				opts = $.extend(cData.options, methodName);
				cData.options = opts;
			} else {
				opts = $.extend(
					{},defaults,
					$.fn.searchselect.parseOptions(this), methodName);
			}

			searchselectload(this,opts);
		});

		function searchselectload(obj,opts){
			//具体实现代码
			if(opts.sourcetype=='codetable'){
				if(opts.parentobjid){
					var option_str = "<option value=''>请选择</option>";
					$(option_str).appendTo($(obj));

					$(obj).comboSelect(opts);
					if(opts.codetable==''){
						opts.codetable=$("#"+opts.parentobjid).attr('codetable');
						$(obj).attr('codetable',opts.codetable);
					}
					$("#"+opts.parentobjid).change(function(e, v) {
						$.ajax({
							url:baseUrl+"codetable/codeSelect.xhtml?codetable=" + opts.codetable + "&parentcode=" + e.target.value,
							dataType:"json",
							success:function(data)
							{
								var option_str = "<option value=''>请选择</option>";
								for(var i = 0; i < data.length; i++){
									code = data[i].code;
									name = data[i].name;
									option_str += "<option value='"+code+"'";
									var select_value = $(obj).attr("text");
									if( select_value &&  (select_value == code || select_value == name)) {
										option_str += " selected";
									}
									option_str += ">" + name + "</option>";
								}
								$(obj).html("");
								$(obj).html(option_str);
								$(obj).comboSelect(opts);
							}
						});
					});

				}else {

					var url = baseUrl+"codetable/codeSelect.xhtml?codetable=" + opts.codetable + "&parentcode=";
					$.ajax({
						url: url,
						type: 'get',
						dataType: 'json',
						async: false,
						success: function (data) {
							var code;
							var name;

							var option_str = "<option value=''>请选择</option>";
							var select_value = $(obj).val();
							for (var i = 0; i < data.length; i++) {
								code = data[i].code;
								name = data[i].name;
								option_str += "<option value='" + code + "'";

								if (select_value && (select_value == code || select_value == name)) {
									option_str += " selected";
								}
								option_str += ">" + name + "</option>";
							}
							$(obj).html("");
							$(option_str).appendTo($(obj));
						},
						error: function (XMLHttpRequest, textStatus, errorThrown) {
						}
					});
					$(obj).comboSelect(opts);
				}
			}else {
				//对应的数据源不是码表的情况
				var urltemp=opts['url'];
				$.ajax({
					url: urltemp,
					type: 'get',
					dataType: 'json',
					async: false,
					success: function (json) {
						//返回格式必须为json [{"code":"","name":""},{"code":"","name":""}]
						var code;
						var name;
						var data = json;
						var option_str = "";
						for(var i = 0; i < data.length; i++){
							code = data[i].code;
							name = data[i].name;
							option_str += "<option value='"+code+"'";
							var select_value = $(obj).attr("text");
							if( select_value &&  (select_value == code || select_value == name)) {
								option_str += " selected";
							}
							option_str += ">" + name + "</option>";
						}
						$(obj).html("");
						$(obj).html(option_str);
						$(obj).comboSelect(opts);
					},
					error: function (XMLHttpRequest, textStatus, errorThrown) {
						var option_str = "<option value=''>请选择</option>";
						$(obj).html("");
						$(obj).html(option_str);
						$(obj).comboSelect(opts);
					}
				});
			}
		}
	}
	$.fn.searchselect.methods = {
		options : function(jq) {
			return $.data(jq[0], "searchselect").options;
		},
		getText:function(jq){
			return '';
		},getValue:function(jq){
			return '';
		}
	};
	$.fn.searchselect.parseOptions=function(obj){
		var t=$(obj);
		return $.extend({},$.parser.parseOptions(obj,['sourcetype','codetable','parentobjid','url']),{});
	};

	/**
	 * 自定义树
	 * methodName 方法名或构造函数的options
	 * arg 方法传参
	 */
	$.fn.customtree = function(methodName,arg) {
		if (typeof methodName == "string") {
			var methodObj = $.fn.menunav.methods[methodName];
			if (methodObj) {
				return methodObj(this, arg);
			} else {
				return this.hybase(methodName, arg);
			}
			return;
		}

		methodName = methodName || {};
		return this.each(function() {
			var cData = $.data(this, "customtree");
			var opts;
			if (cData) {

				opts = $.extend(cData.options, methodName);
				cData.options = opts;
			} else {
				opts = $.extend(
					{},
					$.fn.customtree.parseOptions(this), methodName);
			}

			customtreeload(this,opts);
		});
		function customtreeload(obj,options){
			//具体实现代码
			var customtype=options['customtype'];
			var treeid=options['treeid'];
			var id=options['id'];
			var paras=options['paras'];
			var codetablepara=options['codetablepara'];

			var customonclick= options["onclick"];
			var ismultiselect=options["ismultiselect"];
			var isinput=$(obj).is("input");
			if(isinput)
			{
				$(obj).combotree({
					url:baseUrl+'depart/docustomtree.xhtml?treeid='+treeid+'&type='+customtype+"&paras="+paras+"&codetablepara="+codetablepara,			
					cascadeCheck:false,
					multiple:ismultiselect=="Y"
				});
			}else
			{
				if(ismultiselect=="Y"){
					$(obj).tree({
						url:baseUrl+'depart/docustomtree.xhtml?treeid='+treeid+'&type='+customtype+"&paras="+paras+"&codetablepara="+codetablepara,
						checkbox: true,
						onSelect:function(node){
							if(customonclick!=undefined){
								eval(menuonclick+"(node)");
							}
						}
					});
				}else if(ismultiselect=="N"){
					$(obj).tree({
						url:baseUrl+'depart/docustomtree.xhtml?treeid='+treeid+'&type='+customtype+"&paras="+paras+"&codetablepara="+codetablepara,
						onSelect:function(node){
							if(customonclick!=undefined){
								eval(menuonclick+"(node)");
							}
						}
					});
				}
			}
		}
	}
	$.fn.customtree.parseOptions=function(obj){
		var t=$(obj);
		return $.extend({},$.fn.panel.parseOptions(obj),$.parser.parseOptions(obj,["customtype","treeid","paras","paras","codetablepara","onclick","ismultiselect"]),{});
	};

	/**
	 * 打印组件
	 * methodName 方法名或构造函数的options
	 * arg 方法传参
	 */
	$.fn.print = function(methodName,arg) {
		if (typeof methodName == "string") {
			var methodObj = $.fn.menunav.methods[methodName];
			if (methodObj) {
				return methodObj(this, arg);
			} else {
				return this.hybase(methodName, arg);
			}
			return;
		}

		methodName = methodName || {};
		return this.each(function() {
			var cData = $.data(this, "print");
			var opts;
			if (cData) {

				opts = $.extend(cData.options, methodName);
				cData.options = opts;
			} else {
				opts = $.extend(
					{},
					$.fn.print.parseOptions(this), methodName);
			}

			printload(this,opts);
		});
		function printload(obj,options){
			//具体实现代码
			var sourceid=options['id'];
			var sdivIds=options['divIds'];
			var sprintType=options['printType'];
			var simageType=options['imageType'];
			$("#"+sourceid).click(function (){
				var  LODOP ;
				var  imageType=simageType;
				var divIds=sdivIds;
				var printType =sprintType;
				LODOP=getLodop(document.getElementById('LODOP_OB'), document.getElementById('LODOP_EM'));
				/*	LODOP=getLodop(); */
				if(printType==1||printType==2||printType==3){
					var top = divIds.split(';')[0].split(',')[0];
					var left = divIds.split(';')[0].split(',')[1];
					var width = divIds.split(';')[0].split(',')[2];
					var height = divIds.split(';')[0].split(',')[3];
					var objId = divIds.split(';')[0].split(',')[4];
					if(1==printType){/*图片打印*/
						LODOP.PRINT_INIT("打印控件功能演示_Lodop功能_打印图片");
						if(imageType==0){/*直接打印*/
							/*30,150,400,400*/
							/*LODOP.ADD_PRINT_IMAGE(30,150,400,400,imageHtml);*/
							LODOP.ADD_PRINT_IMAGE(top,left,width,height,objId);
							LODOP.PRINT();
						}else if(imageType==1){/*缩放打印*/
							/*LODOP.ADD_PRINT_IMAGE(30,20,600,250,imageHtml);*/
							LODOP.ADD_PRINT_IMAGE(top,left,width,height,objId);
							LODOP.SET_PRINT_STYLEA(0,"Stretch",1);/*(可变形)扩展缩放模式*/
							LODOP.PREVIEW();
						}else if(imageType==2){/*原图打印*/
							/*LODOP.ADD_PRINT_IMAGE(30,20,600,600,imageHtml);*/
							LODOP.ADD_PRINT_IMAGE(top,left,width,height,objId);
							LODOP.SET_PRINT_STYLEA(0,"Stretch",2);/*按原图比例(不变形)缩放模式*/
							LODOP.PREVIEW();
						}else if(imageType==3){/*打印维护*/
							/*LODOP.ADD_PRINT_IMAGE(30,150,400,400,imageHtml);*/
							LODOP.ADD_PRINT_IMAGE(top,left,width,height,objId);
							LODOP.PRINT_SETUP();
						}
					}else if(2==printType){/*打印表格*/
						LODOP.PRINT_INIT("打印表格");
						/*LODOP.ADD_PRINT_TABLE(10,1,\"99.8%\",\"100%\",document.getElementById(tableDivId).innerHTML);*/
						LODOP.ADD_PRINT_TABLE(top,left,width,height,document.getElementById(objId).innerHTML);
						LODOP.PREVIEW();
					}else if(3==printType){/*打印当前整个页面*/
						LODOP.PRINT_INIT("打印整个页面");
						/*LODOP.ADD_PRINT_HTM(0,0,\"100%\",\"100%\",document.documentElement.innerHTML);*/
						LODOP.ADD_PRINT_HTM(top,left,width,height,document.documentElement.innerHTML);
						LODOP.PREVIEW();
					}
				}else if(4==printType){/*组合打印，多个div块组合成一块打印*/
					LODOP.PRINT_INIT("多个div组合打印");
					LODOP.SET_PRINT_STYLEA(2,"FontSize",18);
					LODOP.SET_PRINT_STYLEA(2,"Bold",1);
					var t=divIds.split(';').length;
					for(var i=0;i<divIds.split(';').length;i++){
						var top = divIds.split(';')[i].split(',')[0];
						var left = divIds.split(';')[i].split(',')[1];
						var width = divIds.split(';')[i].split(',')[2];
						var height = divIds.split(';')[i].split(',')[3];
						var objId = divIds.split(';')[i].split(',')[4];
						LODOP.ADD_PRINT_HTM(top,left,width,height,document.getElementById(objId).innerHTML);

					}
					LODOP.PREVIEW();
				}
			});


		}
	}
	$.fn.print.parseOptions=function(obj){
		var t=$(obj);
		return $.extend({},$.fn.panel.parseOptions(obj),$.parser.parseOptions(obj,["id","divIds","printType","imageType"]),{});
	};

	/**
	 * 富文本
	 * methodName 方法名或构造函数的options
	 * arg 方法传参
	 */
	$.fn.richtext = function(methodName,arg) {
		if (typeof methodName == "string") {
			var methodObj = $.fn.richtext.methods[methodName];
			if (methodObj) {
				return methodObj(this, arg);
			} else {
				return this.hybase(methodName, arg);
			}
			return;
		}
		methodName = methodName || {};
		return this.each(function() {
			var cData = $.data(this, "richtext");
			var opts;
			if (cData) {

				opts = $.extend(cData.options, methodName);
				cData.options = opts;
			} else {
				opts = $.extend(
					{},
					$.fn.richtext.parseOptions(this), methodName);
			}
			richtextload(this,opts);
		});
		function richtextload(obj,options){
			//具体实现代码
			var editor=options['id'];
			ck = CKEDITOR.replace(editor);
			//var t = CKEDITOR.replace( editor);

			/*function show(){
			 alert(t.getData());
			 }*/
			CKEDITOR.config.toolbar_Full =
				[
					{ name: 'document',		items : [ 'Save','NewPage','DocProps','Preview','Print','-','Templates' ] },
					{ name: 'clipboard',	items : [ 'Cut','Copy','Paste','PasteText','PasteFromWord','-','Undo','Redo' ] },
					{ name: 'editing',		items : [ 'Find','Replace','-','SelectAll','-','SpellChecker', 'Scayt' ] },
					{ name: 'forms',		items : [ 'Form', 'Checkbox', 'Radio', 'TextField', 'Textarea', 'Select', 'Button', 'ImageButton', 'HiddenField' ] },
					{ name: 'basicstyles',	items : [ 'Bold','Italic','Underline','Strike','Subscript','Superscript','-','RemoveFormat' ] },
					{ name: 'paragraph',	items : [ 'NumberedList','BulletedList','-','Outdent','Indent','-','Blockquote','CreateDiv','-','JustifyLeft','JustifyCenter','JustifyRight','JustifyBlock','-','BidiLtr','BidiRtl' ] },
					{ name: 'links',		items : [ 'Link','Unlink','Anchor' ] },
					{ name: 'insert',		items : [ 'Image','Table','HorizontalRule','Smiley','SpecialChar','PageBreak','Iframe' ] },//'Flash',
					//'/',换行符
					{ name: 'styles',		items : [ 'Styles','Format','Font','FontSize' ] },
					{ name: 'colors',		items : [ 'TextColor','BGColor' ] },
					{ name: 'tools',		items : [ 'Maximize', 'ShowBlocks','-','About' ] }
				];
			CKEDITOR.config.toolbar = 'Full';
		}
	}
	$.fn.richtext.parseOptions=function(obj){
		var t=$(obj);
		return $.extend({},$.fn.panel.parseOptions(obj),$.parser.parseOptions(obj,["id","name","rows","cols"]),{});
	};

	$.fn.richtext.methods = {
		getValue:function(obj)
		{
			return ck.getData();
		}
	};

	/**
	 * radio单选
	 * methodName 方法名或构造函数的options
	 * arg 方法传参
	 */
	$.fn.radio = function(methodName,arg) {
		if (typeof methodName == "string") {
			var methodObj = $.fn.menunav.methods[methodName];
			if (methodObj) {
				return methodObj(this, arg);
			} else {
				return this.hybase(methodName, arg);
			}
			return;
		}
		methodName = methodName || {};
		return this.each(function() {
			var cData = $.data(this, "radio");
			var opts;
			if (cData) {

				opts = $.extend(cData.options, methodName);
				cData.options = opts;
			} else {
				opts = $.extend(
					{},
					$.fn.radio.parseOptions(this), methodName);
			}
			radioload(this,opts);
		});
		function radioload(obj,options){
			//具体实现代码
			var fin="";
			var id=options['id'];
			var name=options['name'];
			var opt=options['options'];
			var checkopt=options['checkoptions'];
			opt=$.trim(opt);
			checkopt=$.trim(checkopt);

			var tt=opt.split(';').length;
			for(var i=0;i<opt.split(';').length;i++){
				var optfirst = opt.split(';')[i].split(':')[0];
				var optsecond = opt.split(';')[i].split(':')[1];

				if(checkopt==optsecond){
					//fin=fin+"<label><input type=\"radio\" name=\""+name+"\" checked=\"checked\" />"+optfirst+"</label>";
					fin=fin+"<label><input type=\"radio\" name=\""+name+"\" checked=\"checked\""+"value=\""+optsecond+"\"/>"+optfirst+"</label>";
				}else{
					//fin=fin+"<label><input type=\"radio\" name=\""+name+"\"/>"+optfirst+"</label>";
					fin=fin+"<label><input type=\"radio\" name=\""+name+"\""+"value=\""+optsecond+"\"/>"+optfirst+"</label>";
				}
			}
			//$("#"+id).html(fin);
			//$(obj).replaceWith(fin);
			$(obj).html(fin);
		}
	}
	$.fn.radio.parseOptions=function(obj){
		var t=$(obj);
		return $.extend({},$.fn.panel.parseOptions(obj),$.parser.parseOptions(obj,["options","checkoptions","name","id"]),{});
	};


	/**
	 * checkbox多选
	 * methodName 方法名或构造函数的options
	 * arg 方法传参
	 */
	$.fn.checkbox = function(methodName,arg) {
		if (typeof methodName == "string") {
			var methodObj = $.fn.menunav.methods[methodName];
			if (methodObj) {
				return methodObj(this, arg);
			} else {
				return this.hybase(methodName, arg);
			}
			return;
		}
		methodName = methodName || {};
		return this.each(function() {
			var cData = $.data(this, "checkbox");
			var opts;
			if (cData) {

				opts = $.extend(cData.options, methodName);
				cData.options = opts;
			} else {
				opts = $.extend(
					{},
					$.fn.checkbox.parseOptions(this), methodName);
			}
			checkboxload(this,opts);
		});
		function checkboxload(obj,options){
			//具体实现代码
			var fin="";
			var id=options['id'];
			var name=options['name'];
			var opt=options['options'];
			var checkopt=options['checkoptions'];
			opt=$.trim(opt);
			checkopt=$.trim(checkopt);

			var tt=opt.split(';').length;
			for(var i=0;i<opt.split(';').length;i++){
				var optfirst = opt.split(';')[i].split(':')[0];
				var optsecond = opt.split(';')[i].split(':')[1];

				var ischeck=false;
				for(var j=0;j<checkopt.split(',').length;j++){
					var tempcheck=checkopt.split(',')[j];
					tempcheck=$.trim(tempcheck);
					if(tempcheck==optsecond){
						ischeck=true;
						break;
					}
				}
				if(ischeck){
					fin=fin+"<label><input type=\"checkbox\" name=\""+name+"\" checked=\"checked\""+"value=\""+optsecond+"\"/>"+optfirst+"</label>";
				}else{
					fin=fin+"<label><input type=\"checkbox\" name=\""+name+"\""+"value=\""+optsecond+"\"/>"+optfirst+"</label>";
				}
			}
			//$("#"+id).html(fin);
			//$(obj).replaceWith(fin);
			$(obj).html(fin);
		}
	}
	$.fn.checkbox.parseOptions=function(obj){
		var t=$(obj);
		return $.extend({},$.fn.panel.parseOptions(obj),$.parser.parseOptions(obj,["options","checkoptions","name","id"]),{});
	};


	$.fn.hybase = function(methodName, arg) {
		if (typeof methodName == "string") {
			var methodObj = $.fn.hybase.methods[methodName];
			if (methodObj) {
				return methodObj(this, arg);
			} else {
				return;
			}
		}
	}
	$.fn.hybase.methods = {
		options : function(jq) {
			return $.data(jq[0], "hybase").options;
		},
		getValue:function(obj)
		{
			var values="";
            if($(obj[0]).is("input")) {
                var t = $(obj[0]).combotree("tree");
                var nodes = t.tree('getSelected');
                values = nodes.id;
            }else{
                var nodes = $(obj[0]).tree("getSelected");
                values = nodes.id;
            }
			return values;
		},
		getALLValue:function(obj)
		{
			var values="";
			var length1=$(obj[0]).tree('getChecked').length;
			for(var i=0;i<length1;i++){
				var temp=$(obj[0]).tree('getChecked')[i];
				values+=temp.id+",";
			}
			return values;
		},
		getselected : function() {
			var nodes = $(this).tree('getChecked');
			var s = '';
			for (var i = 0; i < nodes.length; i++) {
				if (s != '')
					s += ',';
				s += nodes[i].id;
			}
			return s;
		}
	};

})(jQuery);







function getexportdatauri()
{
	return baseUrl+"common/doExcelExport.xhtml";
}

//导出当前页数据
function exportpagedata(obj)
{
	var url=getexportdatauri();
	var tab= obj.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.childNodes[0].childNodes[2];
	var tableId=tab["id"];
	var opts = $('#'+tableId).datagrid('options');
	var columns=opts["columns"];
	var exportDataInfo=opts["exportDataInfo"];

	var data=JSON.stringify($('#'+tableId).datagrid('getData'));
	var paramdata=JSON.stringify({columns:columns,exportDataInfo:exportDataInfo});

	var form = $("<form>");
	form.attr('style', 'display:none');
	form.attr('target', '_self');
	form.attr('method', 'post');
	form.attr('action', url);

	var input1 = $('<input>');
	input1.attr('type', 'hidden');
	input1.attr('name', 'paramdata');
	input1.attr('value', paramdata);

	var input2 = $('<input>');
	input2.attr('type', 'hidden');
	input2.attr('name', 'data');
	input2.attr('value', data);

	$('body').append(form);
	form.append(input1);
	form.append(input2);

	form.submit();
	form.remove();
}

//导出所有数据
function exportalldata(obj)
{
	var url=getexportdatauri();
	var tab= obj.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.childNodes[0].childNodes[2];
	var tableId=tab["id"];
	var opts = $('#'+tableId).datagrid('options');
	var dataurl=opts["url"];
	var queryParams=opts["queryParams"];
	var columns=opts["columns"];
	var paramdata=JSON.stringify({columns:columns});

	var paramdata={page:'1',rows:'999999'};
	var arr=queryParams.split("&");
	for(var item in arr){
		if(typeof item  === 'string'){
			var itemstring=decodeURIComponent(arr[item]);
			var pos=itemstring.indexOf("=");
			var kk=itemstring.substring(0,pos);
			var vv=itemstring.substring(pos+1);

			if(paramdata.hasOwnProperty(kk)){
				paramdata[kk]=paramdata[kk]+','+vv;
			}else{
				paramdata[kk]=vv;
			}
		}
	}

	$.ajax({
		type: "POST",
		url: dataurl,
		data:paramdata,
		success: function(result){
			var form = $("<form>");
			form.attr('style', 'display:none');
			form.attr('target', '_self');
			form.attr('method', 'post');
			form.attr('action', url);
			form.attr('enctype','multipart/form-data');

			var input1 = $('<input>');
			input1.attr('type', 'hidden');
			input1.attr('name', 'paramdata');

			var v1=JSON.stringify({columns:columns});
			input1.attr('value', v1);

			var input2 = $('<input>');
			input2.attr('type', 'hidden');
			input2.attr('name', 'data');
			var v2=JSON.stringify(result);
			input2.attr('value',v2);

			$('body').append(form);
			form.append(input1);
			form.append(input2);

			form.submit();
			form.remove();
		}
	});
}


var arry = [];

function getOptionsi(id){
	
	for(var i=0;i<arry.length;i++){
		if(id==arry[i].id){
			return arry[i];
		}
	}
}


(function($) {
	/**
	 * 图片上传/附件
	 * methodName 方法名或构造函数的options
	 * arg 方法传参
	 */
	$.fn.attupload = function(methodName,arg) {
		var defaults={
			id:"",
			fileType:"0",
			numPerRow:"5" ,
			imageWidth:"120" ,
			imageHeight:"160",
			dataRight:"1" ,
			picShowDivId:"pic",
			nameSuffix:"jpg",
			maxFileSize:"100000000",
			maxFileCount:"5" ,
			alreadyFileCount:"0",
			osmFlag:"0"
				
		};

		if (typeof methodName == "string") {
			var methodObj = $.fn.attupload.methods[methodName];
			if (methodObj) {
				return methodObj(this, arg);
			} else {
				return this.hybase(methodObj, arg);
			}
			return;
		}

		methodName = methodName || {};
		return this.each(function() {
			var cData = $.data(this, "attupload");
			var opts;
			if (cData) {
				opts = $.extend(cData.options, methodName);
				cData.options = opts;
			} else {
				opts = $.extend(
					{},defaults,
					$.fn.attupload.parseOptions(this), methodName);
			}

			
			var exdate=new Date();
			exdate.setDate(exdate.getDate()+1);
			opts.id = "id"+arry.length;
			arry.push({id:"id"+arry.length,alreadyFileCount:0,numFlag:$("#errorLog").length});
			attuploadload(this,opts);
		});

		function attuploadload(obj,options){

			/**
			 *
			 * <div id="pic"></div>
			 <div class="result-list">
			 <h1 class="title">附件列表</h1>
			 <table id="tt" style="width:100%;"></table> </div>

			 */
			if(options.fileType=="1"){
				options["picShowDivId"]=options["resultlistDiv"];
				if($("#"+options["picShowDivId"]).length==0){
					$(obj).after("<div id='"+options["picShowDivId"]+"'></div>");
				}
			}
			else{
				if($("#"+options["resultlistDiv"]).length>0){
					var afterHtml ="";
					//afterHtml = afterHtml + "";
					// alert(options["resultlistDiv"].substring(1,options["resultlistDiv"].length));
					afterHtml = afterHtml + "<div class='result-list'  \">";
					afterHtml = afterHtml + "<h1 class=\"title\">附件列表</h1>";
					afterHtml = afterHtml + "<table id=\"tt"+options["resultlistDiv"]+"\" style=\"width:100%;\"></table> </div>";
					$("#"+options["resultlistDiv"]).html(afterHtml);
				}else{
					var afterHtml ="";
					afterHtml = afterHtml + "<div class='result-list' id=\""+options["resultlistDiv"]+"\">";
					afterHtml = afterHtml + "<h1 class=\"title\">附件列表</h1>";
					//alert($(".result-list").length);
					var aa = $(".result-list").length ;
					//alert(aa);
					afterHtml = afterHtml + "<table id=\"tt"+options["resultlistDiv"]+"\" style=\"width:100%;\"></table> </div>";
					$(obj).after(afterHtml);
				}
			}
			
			
			
			
			
			
			//var identify = document.cookie.split("=")[1];
			//$(identify).data("maxFileCount",options["maxFileCount"]);
			if (options["fileType"] == '1') {
				//$("#"+options["resultlistDiv"]).css("display", "none");
				loadImage(obj,options);
			}else {
				doQuery(options,"tt"+options["resultlistDiv"]);
			}
			
			if (options["dataRight"] == '0') {
				$("#fileuploader").css('display', 'none');
				$(obj).css("display","none");
			}
			var osmFlag ="0";
			if(options["osmFlag"]==undefined)
				osmFlag ="0";
			else
				osmFlag =options["osmFlag"];
				
			$(obj).uploadFile({
				unicode:options.id,
				url: baseUrl+"upload/doupload.xhtml?vchr_domain="+options["vchr_domain"]+"&fileType="+options["fileType"]+"&vchr_entityid="+options["vchr_entityid"]+"&osmFlag="+osmFlag,
				fileName: "myfile",
				allowedTypes:options["nameSuffix"],//$("#attrs").attr("nameSuffix")
				multiple: true,
				enctype: "multipart/form-data",
				showProgress: false,
				showDelete: false,
				maxFileCount: 1,
				maxFileSize:options["maxFileSize"] ,//$("#attrs").attr("maxFileSize")
				showStatusAfterSuccess: true,
				showStatusAfterError: true,
				showDownload: false,
				downloadCallback: true,
				showView: false,
				showFileSize: false,
				deleteCallback: function(data, pd) {
					var filename = pd.filename[0].innerText.split('(')[0];
					//alert(filename);
				},
				onSuccess: function(files, response, xhr, pd) {
					$("div[class='ajax-file-upload-container']").remove();
					$.messager.alert("提示信息", "上传成功！", "info",
						function() {});
					if (options["fileType"] == '1'||options["fileType"] ==1) {
						$(obj).attupload("loadImage",options);
						
						
					} else {
		 				$('#tt'+options.resultlistDiv).datagrid("reload");
					}
				},
				onError: function(files, status, message, pd) {
					alert("上传失败");
				},
				onSelect: function(files) {
					//alert($("#"+options.id).length) ;
					//alert(options.maxFileCount + "==" +options.alreadyFileCount );
					var op = getOptionsi(options.id);
					//alert(JSON.stringify(op));
					//alert(options.maxFileCount +"=="+ op.alreadyFileCount);
					//alert($("#errorLog").length);
					if(options.maxFileCount <= op.alreadyFileCount&&options.fileType=="1"){
						$("<div class='" + "'><b>" + "您上传的图片已经超过最大数量" +options.maxFileCount+"</b> " +  "</div>").appendTo($("#errorLog"+options.id+""));
						var form = $("#form"+options.id)[0] ;
						form.reset();
						return false ;
					}
					if(options.maxFileCount <= op.alreadyFileCount&&options.fileType!="1"){
						$("<div class='" + "'><b>" + "您上传的附件已经超过最大数量" +options.maxFileCount+"</b> " +  "</div>").appendTo($("#errorLog"+options.id+""));
						var form = $("#form"+options.id) ;
						form.reset();
						return false ;
					}
					
				},
				viewCallback: function(data, pd) {
					var filename = pd.filename[0].innerText.split('(')[0];
					alert(filename);
				},
				downloadCallback: function(data) {
					alert(data);
				}
			});

		}
		
	
		
	}
	$.fn.attupload.methods = {
		options : function(jq) {
			return $.data(jq[0], "attupload").options;
		},
		view:function(obj,option){
			//alert(option.id);
			openWinW(baseUrl+'upload/gotoView.xhtml?id=' + option.id, "查看附件信息", "500px", "290px", false, false);
		},
		del:function(obj,option) {

			$.messager.confirm("提示信息", "确定要删除选择的数据吗？",
				function(result) {
				 var id="";
                    if(option.fileType=="1")
                    	id =option.idd;
                    else 
                    	id=option.id;
					if (result == true) {
						$.ajax({
							url: baseUrl+"upload/gotoDelete.xhtml?ids=" + id+"&random="+Math.random(),
							success: function(msg) {
								//alert("msg====="+$(this).data('opts'));
								if ("success" == msg) {//$("#attrs").attr("alreadyFileCount",obj.rows.length)
									if (option.alreadyFileCount == option.alreadyFileCount) {
										$(".ajax-file-upload-error").remove();
									}
									//$("#attrs").attr("alreadyFileCount",$("#attrs").attr("alreadyFileCount")- 1);
									$.messager.alert("提示", "删除操作成功！", "info",
										function() {});
									if (option.fileType == '1'||option.fileType == 1) {
										$(obj).attupload("loadImage",option);
										//loadImage(option);
									} else {
										$('#tt'+option.resultlistDiv).datagrid("reload");
									}
								} else {
									$.messager.alert("提示", "操作失败", "info",
										function() {});
								}
							}
						});
					}
				});
		},
		loadImage:function(obj,options) {
			//alert("loadImage::"+options.id);
			var op = getOptionsi(options.id);
			$.ajax({
				url: baseUrl+"upload/loadImage.xhtml?vchr_domain="+options["vchr_domain"]+"&fileType="+options["fileType"]+"&vchr_entityid="+options["vchr_entityid"]+"&Random="+Math.random(),
				datatype: "json",
				success: function(res) {
					if (res != 'failure') {
						var obj = JSON.parse(res);
						var tabStr = "<table class='hy-upload-imagetable'><tr>";
						if (obj && obj.rows) {
							//var identify= document.cookie.split("=")[1];
							//$(identify).data("alreadyFileCount",obj.rows.length);
							//$("#attrs").attr("alreadyFileCount",obj.rows.length);
							//alert($("#attrs").attr("alreadyFileCount"));
							//$("#alreadyFileCount").val(obj.rows.length);
							//options.alreadyFileCount = obj.rows.length;
							//alert("111:::::"+obj.rows.length);
							var alreadyFileCount =0;
							if(op!=null){
								 op.alreadyFileCount = obj.rows.length;
								 alreadyFileCount =obj.rows.length;
								 //alert(op.alreadyFileCount);
							}
							if(alreadyFileCount<=options.maxFileCount){
								$("#errorLog"+options.id).html("");
							}
							for (var i = 0; i < obj.rows.length; i++) {

								if (i % options["numPerRow"] == 0) {
									tabStr = tabStr + "<tr>";
								}
								var oo = obj.rows[i];
								var aa= $.extend( {}, options, {idd:""+oo.vchr_id+""} );
								var bb= JSON.stringify(aa);
								var fileName = oo.vchr_originname ;
								if(fileName.length>10)
									fileName=fileName.substring(0,9);
								//tabStr = tabStr + "<td align='center'><div> <image style='cursor:pointer;' height="+options["imageHeight"]+" width="+options["imageWidth"]+" onClick=$('#attupload').attupload('show',"+JSON.stringify($.extend( {}, options, {src:""+baseUrl+"upload/getPreview.xhtml?fileName=" + oo.vchr_storagename + "&vchr_domain=" + oo.vchr_domain + "&vchr_entityid=" + oo.vchr_entityid + "&vchr_id=" + oo.vchr_id+""} ))+") src='"+baseUrl+"upload/getPreview.xhtml?fileName=" + oo.vchr_storagename + "&vchr_domain=" + oo.vchr_domain + "&vchr_entityid=" + oo.vchr_entityid + "&vchr_id=" + oo.vchr_id + "' /></div>    <div><font size='2' title='"+oo.vchr_originname+"' >" +  fileName + " </font>" + "<a onclick=$('#attupload').attupload('del',"+bb+") style='cursor:pointer;'><image src='"+baseUrl+"images/close_r.png'/></a>" + "</div> </td>";
								
								tabStr = tabStr + "<td align='center' ><div> <image style='cursor:pointer;' height="+options["imageHeight"]+" width="+options["imageWidth"]+" onClick=$('#attupload').attupload('show',"+JSON.stringify($.extend( {}, options, {src:""+baseUrl+"upload/getPreview.xhtml?fileName=" + oo.vchr_storagename + "&vchr_domain=" + oo.vchr_domain + "&vchr_entityid=" + oo.vchr_entityid + "&vchr_id=" + oo.vchr_id+""} ))+") src='"+baseUrl+"upload/getPreview.xhtml?fileName=" + oo.vchr_storagename + "&vchr_domain=" + oo.vchr_domain + "&vchr_entityid=" + oo.vchr_entityid + "&vchr_id=" + oo.vchr_id + "' /></div>    <div><font size='2' title='"+oo.vchr_originname+"' >" +  fileName + " </font>"
								+ "<a onclick=$('#attupload').attupload('del',"+bb+") style='cursor:pointer;'>"
								if(options.dataRight=="1"){
									tabStr = tabStr+	"<image src='"+baseUrl+"images/close_r.png'/></a>";
								}else{
									$(obj1).css("display","none");
									tabStr = tabStr+"</a>";
								}
								tabStr = tabStr + "</div> </td>";
								
								if (i % options["numPerRow"] == options["numPerRow"]-1) {
									tabStr = tabStr + "</tr>";
								}
							}

							if (i % options["numPerRow"] != 0) {
								tabStr = tabStr + "</tr></table>";
							} else {
								tabStr = tabStr + "</table>";
							}
						}
						$("#"+options["picShowDivId"]).html(tabStr);
					}
				},
				error: function(res) {
					$.messager.alert("提示信息", "出错啦 ", "info",
						function() {});
				}
			});
		},
		show:function(obj,option){
			window.parent.showw(option.src);
		}

	};

	$.fn.attupload.parseOptions=function(obj){
		var t=$(obj);
		return $.extend({},$.fn.panel.parseOptions(obj),$.parser.parseOptions(obj,["fileType","vchr_entityid",
			"vchr_domain","numPerRow",
			"imageWidth","imageHeight",
			"dataRight",
			"nameSuffix","maxFileSize",
			"maxFileCount",
			"resultlistDiv","osmFlag"]),{});
	};

	function doQuery(options,id) {
		//alert(JSON.stringify( options["vchr_domain"] ));
		//alert(options["vchr_domain"]+""+options["vchr_entityid"]);
		var data_attr = "";
		$('#'+id).datagrid({
			url: baseUrl+"upload/queryList.xhtml?vchr_domain="+options["vchr_domain"]+"&fileType="+options["fileType"]+"&vchr_entityid="+options["vchr_entityid"]+"&Random="+Math.random(),
			queryParams: data_attr,
			fitColumns: true,
			rownumbers: true,
			pagination: true,
			pageNumber: 1,
			columns: [[{
				field: 'vchr_originname',
				title: '文件名',
				width: 120
			},
				{
					field: 'date_uploaddate',
					title: '上传时间',
					width: 120
				},
				{
					field: 'vchr_id',
					title: '操作',
					width: 100,
					formatter: function(value, rowData, rowIndex) {
						var html = "";//options["dataRight"]
						//alert(JSON.stringify(options));
						var aa= $.extend( {}, options, {id:""+value+""} );
						var bb= JSON.stringify(aa);

						//alert(bb);
						//alert(JSON.stringify(aa));
						html += "<span title=查看  class=btn-view onclick=$('#attupload').attupload(\"view\","+bb+")></span>";
						if (options["dataRight"] == '1' && options["fileType"]!= '1') {
							html += "<span title=删除  class=btn-delete onclick=$('#attupload').attupload('del',"+bb+")></span>";
						}

						/*
						 *
						 * <a
						 href="<%=basePath %>upload/download.xhtml?id=${model.vchr_id }&vchr_domain=${model.vchr_domain}&vchr_entityid=${model.vchr_entityid}"
						 title="点击下载" class="color1" target="_blank"
						 onclick="javascript:void(0);"> ${model.vchr_originname } </a>
						 */
						var downStr = " <span title=下载  ><a href=\""+baseUrl+"upload/download.xhtml?id="+rowData.vchr_id+"&vchr_domain="+rowData.vchr_domain+"&vchr_entityid="+rowData.vchr_entityid+"\""+
							"title=\"点击下载\" class=\"color1\" target=\"_blank\""+
							"onclick=\"javascript:void(0);\"> <img src='images/download.png'/> </a></span>";
						html = html + downStr;
						return html;
					}
				}]],
				onLoadSuccess:function(data){
					
					var op = getOptionsi(options.id);
				    if(op!=null)
				    {
				    	op.alreadyFileCount = data.total;
					    alreadyFileCount =data.total;
					}
					if(alreadyFileCount<=options.maxFileCount){
						$("#errorLog"+options.id).html("");
					}
				}
		});
	}

	function show(value) {
		window.parent.showw(value);
	}

	function loadImage(obj1,options) {
		//alert("options.id"+options.id);
		var op = getOptionsi(options.id);
		$.ajax({
			url: baseUrl+"upload/loadImage.xhtml?vchr_domain="+options["vchr_domain"]+"&fileType="+options["fileType"]+"&vchr_entityid="+options["vchr_entityid"]+"&Random="+Math.random(),
			datatype: "json",
			success: function(res) {
				if (res != 'failure') {
					var obj = JSON.parse(res);
					if (obj && obj.rows) {
						var j = 0;
						//var identify = document.cookie.split("=")[1];
						//$(identify).data("alreadyFileCount",obj.rows.length);
						//alert($("#attrs").attr("alreadyFileCount"));
						//$("#alreadyFileCount").val(obj.rows.length);
						var alreadyFileCount =0;
						if(op!=null){
							op.alreadyFileCount = obj.rows.length;
							 alreadyFileCount =obj.rows.length;
						}
						if(alreadyFileCount<=options.maxFileCount){
							$("#errorLog"+options.id).html("");
						}
						var tabStr = "<table class='hy-upload-imagetable'><tr>";
						for (var i = 0; i < obj.rows.length; i++) {

							if (i % options["numPerRow"] == 0) {
								tabStr = tabStr + "<tr>";
							}
							var oo = obj.rows[i];//imageHeight="120" imageWidth="160"
							//alert(JSON.stringify(options));
//							var aa= $.extend( {}, options);
							var aa= $.extend( {}, options, {idd:""+oo.vchr_id+""} );
							var bb= JSON.stringify(aa);
							var fileName = oo.vchr_originname ;
							if(fileName.length>10)
								fileName=fileName.substring(0,9);
							//tabStr = tabStr + "<td align='center'><div> <image style='cursor:pointer;' height="+options["imageHeight"]+" width="+options["imageWidth"]+" onClick=$('#attupload').attupload('show',"+JSON.stringify($.extend( {}, options, {src:""+baseUrl+"upload/getPreview.xhtml?fileName=" + oo.vchr_storagename + "&vchr_domain=" + oo.vchr_domain + "&vchr_entityid=" + oo.vchr_entityid + "&vchr_id=" + oo.vchr_id+""} ))+") src='"+baseUrl+"upload/getPreview.xhtml?fileName=" + oo.vchr_storagename + "&vchr_domain=" + oo.vchr_domain + "&vchr_entityid=" + oo.vchr_entityid + "&vchr_id=" + oo.vchr_id + "' /></div>    <div><font size='2' title='"+oo.vchr_originname+"' >" +  fileName + " </font>" + "<a onclick=$('#attupload').attupload('del',"+bb+") style='cursor:pointer;'><image src='"+baseUrl+"images/close_r.png'/></a>" + "</div> </td>";
							
							tabStr = tabStr + "<td align='center'><div> <image style='cursor:pointer;' height="+options["imageHeight"]+" width="+options["imageWidth"]+" onClick=$('#attupload').attupload('show',"+JSON.stringify($.extend( {}, options, {src:""+baseUrl+"upload/getPreview.xhtml?fileName=" + oo.vchr_storagename + "&vchr_domain=" + oo.vchr_domain + "&vchr_entityid=" + oo.vchr_entityid + "&vchr_id=" + oo.vchr_id+""} ))+") src='"+baseUrl+"upload/getPreview.xhtml?fileName=" + oo.vchr_storagename + "&vchr_domain=" + oo.vchr_domain + "&vchr_entityid=" + oo.vchr_entityid + "&vchr_id=" + oo.vchr_id + "' /></div>    <div><font size='2' title='"+oo.vchr_originname+"' >" +  fileName + " </font>"
							+ "<a onclick=$('#attupload').attupload('del',"+bb+") style='cursor:pointer;'>"
							if(options.dataRight=="1"){
								tabStr = tabStr+	"<image src='"+baseUrl+"images/close_r.png'/></a>";
							}else {
								$(obj1).css("display","none");
								tabStr = tabStr+"</a>";
							}
							
							
							if (i % options["numPerRow"] == options["numPerRow"]-1) {
								tabStr = tabStr + "</tr>";
							}
						}

						if (i % options["numPerRow"] != 0) {
							tabStr = tabStr + "</tr></table>";
						} else {
							tabStr = tabStr + "</table>";
						}
					}
					/*alert($("#"+options["picShowDivId"]).length);
					alert(tabStr);*/
					//alert($("#"+options["picShowDivId"]).length);
					$("#"+options["picShowDivId"]).html(tabStr);
				}
			},
			error: function(res) {
				$.messager.alert("提示信息", "出错啦 ", "info",
					function() {});
			}
		});
	}




})(jQuery);



(function($) {
	/**
	 * 菜单树
	 * methodName 方法名或构造函数的options
	 * arg 方法传参
	 */
	$.fn.menutree = function(methodName,arg) {
		if (typeof methodName == "string") {
			var methodObj = $.fn.menutree.methods[methodName];
			if (methodObj) {
				return methodObj(this, arg);
			} else {
				return this.hybase(methodObj, arg);
			}
			return;
		}

		methodName = methodName || {};
		return this.each(function() {
			var cData = $.data(this, "menutree");
			var opts;
			if (cData) {
				opts = $.extend(cData.options, methodName);
				cData.options = opts;
			} else {
				opts = $.extend(
					{},
					$.fn.menutree.parseOptions(this), methodName);
			}

			menutreeload(this,opts);
		});

		function menutreeload(obj,options){

			var checkbox = options["checkbox"];
			//alert(typeof checkbox);
			var checkedvalue = options["checkedvalue"];
			//alert(typeof checkedvalue);
			if(checkedvalue==undefined)
				checkedvalue = "";
			if(checkbox==undefined) checkbox=false;
			else if(checkbox=="1")
				checkbox=true;
			else if(checkbox=="0"){
				checkbox=false;
			}
			//alert(checkbox);
			var showOperate = options["showOperate"];
			if(showOperate==undefined) showOperate="0";
			else if(showOperate!="1"&&showOperate!="0")
				showOperate="0";

			var isreadonly = options["isreadonly"];
			if(isreadonly==undefined) isreadonly="0";
			else if(isreadonly!="1"&&isreadonly!="0")
				isreadonly="0";
			
			var applyRight = options["applyRight"];
			if(applyRight==undefined) applyRight="1";
			
			var showSystemId = options["showSystemId"];
			if(showSystemId==undefined) showSystemId="";

			var menuonclick= options["onclick"];
			var rootFlag=false;
			var beginChildFlag=false;
			var tmpNode=null;
			var checkedAll=true;
			
            var url = baseUrl+'/role/doMenuTree.xhtml?showOperate='+showOperate+'&checked='+checkedvalue+"&applyRight="+applyRight;
			if(options["showAll"]=="1")
			url = url +"&showAll=all";
			else 
				url = url +"&showAll=none";
			url = url +"&showSystemId="+showSystemId ;
			$(obj).tree({
				url:url,
				animate:true,
				checkbox:checkbox,
				cascadeCheck:false,
				onBeforeExpand:function(node,param){
				},
				onSelect:function(node){
					if(menuonclick!=undefined){
						eval(menuonclick+"(node)");
					}
				},
				onCheck:function(node, checked){
				   // alert(JSON.stringify(node));
					if(rootFlag&&checked){
						rootFlag =false ;
						beginChildFlag=false;
						tmpNode=null;
						return ;
					}
						
					if(checked){
						if(!beginChildFlag){
							beginChildFlag=true;
							tmpNode=node;
						}
						//if(node.id.length==32||node.code=="console")
						/*if(node.parent_id==null||node.parent_id=="")
							rootFlag=true;*/
						//alert(beginChildFlag+"::"+rootFlag);
						if(beginChildFlag){//找到最上层之后，
							var getChildrenNode = $(obj).tree('getChildren', tmpNode.target);
							if(getChildrenNode != null) {//遍历子孙节点，选中
								for(var i=0;i<getChildrenNode.length;i++){
									if(getChildrenNode[i].parent_id!= tmpNode.parent_id)
									$(obj).tree('check', getChildrenNode[i].target);
								}
							}
							//alert(beginChildFlag+"::"+rootFlag);
							//rootFlag=false;
							
						}

						if(checked){//找到最上层，停止执行
							var parentNode = $(obj).tree('getParent', node.target);//找到父节点
							if(parentNode!=null){
								if(parentNode.parent_id==null||parentNode.parent_id==""){
									rootFlag = true ;
								}
								if (parentNode != null) {//级联递归选中上级节点
									$(obj).tree('check', parentNode.target);
								}
							}
						}
					}else{//级联取消子孙节点

						//if(node.parent_id==""||node.parent_id==null){
							rootFlag=false;
							beginChildFlag=false;
							tmpNode=null;
						//}
						var getChildrenNode = $(obj).tree('getChildren', node.target);
						if(getChildrenNode != null) {
							for(var i=0;i<getChildrenNode.length;i++){
								$(obj).tree('uncheck', getChildrenNode[i].target);
							}
						}
					}
				},
				onLoadSuccess:function(node,data){
					if("1"==isreadonly){
						$(obj).find('span.tree-checkbox').unbind().click(function(){
							return false;
						});
					}
					if("0"==showOperate){

						var getChildrenNode = $(obj).tree('getChildren');
						for(var i=0;i<getChildrenNode.length;i++){
							var node = getChildrenNode[i];
							if(node.parent_id==""||node.parent_id==null){
								var url =baseUrl+ "/subsys/gotoView.xhtml?id="+node.id+"&showFlag=0";
                                $("#treeFrame").attr("src",url);
								$(obj).tree('select',node.target);
								break;
							}
						}

					}

				}
			});
		}
	}
	$.fn.menutree.methods = {
		options : function(jq) {
			return $.data(jq[0], "menutree").options;
		},getCheckedValues:function(jq){
			var nodes = $(jq).tree('getChecked');
			var s = "";
			var operateIds="";
			var sysIds="";
			for(var i=0; i<nodes.length; i++){
				if(nodes[i].id.indexOf("operate")==0)
					operateIds+="3"+nodes[i].code+",";
				else if(nodes[i].parent_id==""||nodes[i].parent_id==null)
					sysIds+="1"+nodes[i].id+",";
				else
				s += "2"+nodes[i].code+",";
			}
			alert(s+operateIds+sysIds);
			return s+operateIds+sysIds;
		}
	};

	$.fn.menutree.parseOptions=function(obj){
		var t=$(obj);
		return $.extend({},$.fn.panel.parseOptions(obj),$.parser.parseOptions(obj,["checkedvalue","showOperate","checkbox","isreadonly","onclick","showAll","applyRight","showSystemId"]),{});
	};

})(jQuery);



(function($) {
	/**
	 * 头像上传组件
	 * methodName 方法名或构造函数的options
	 * arg 方法传参
	 */
	$.fn.photoupload = function(methodName,arg) {

		var defaults = {
			id:"",
			imgid:"",
			width:"120",
			height:"200",
			filename:"",
			picture_name:"",
			edit:"0"

		};
		if (typeof methodName == "string") {
			var methodObj = $.fn.photoupload.methods[methodName];
			if (methodObj) {
				return methodObj(this, arg);
			} else {
				return this.hybase(methodObj, arg);
			}
			return;
		}

		methodName = methodName || {};
		return this.each(function() {
			var cData = $.data(this, "photoupload");
			var opts;
			if (cData) {
				opts = $.extend(cData.options, methodName);
				cData.options = opts;
			} else {
				opts = $.extend(
					{},defaults,
					$.fn.photoupload.parseOptions(this), methodName);
			}

			photoupload(this,opts);
		});

		function photoupload(obj,options){
			
			if($("#"+options["imgid"]).length==0){//如果展示图片的div不错存在，则
				$(obj).before("<div id='"+options["imgid"]+"'></div>");
			}
			if(options.edit=="1"){
				$(obj).html(" <A class=btn_addPic href=\"javascript:void(0);\"><SPAN><EM>+</EM>选择图片</SPAN> "+
						"<INPUT  onchange=\"previewImage(this,'imghead"+options["id"]+"','"+options["imgid"]+"','"+options["width"]+"','"+options["height"]+"','"+options["picture_name"]+"','file"+options["id"]+"')\"  class=filePrew  id=\"file"+options["id"]+"\" name=\"file\""+
						" title=支持jpg、jpeg、gif、png格式， tabIndex=3 type=\"file\" size=3 name=pic  ></A>");
			}
			$("#"+options["imgid"]).html("<image id= 'imghead"+options["id"]+"' width='"+options["width"]+"'  height='"+options["height"]+"'  src='upload/getPreview.xhtml?fileName="+options["filename"]+"' />");

		}
	}
	$.fn.photoupload.methods = {
		options : function(jq) {
			return $.data(jq[0], "photoupload").options;
		}
	};

	$.fn.photoupload.parseOptions=function(obj){
		var t=$(obj);
		return $.extend({},$.fn.panel.parseOptions(obj),$.parser.parseOptions(obj,["id","imgid","width","height","filename","picture_name","edit"]),{});
	};

})(jQuery);


var tmp_obj_id;
(function($) {
	/**
	 *
	 * methodName 方法名或构造函数的options
	 * arg 方法传参
	 */
	$.fn.searchinput = function(methodName,arg) {
		if (typeof methodName == "string") {
			var methodObj = $.fn.searchinput.methods[methodName];
			if (methodObj) {
				return methodObj(this, arg);
			} else {
				return this.hybase(methodObj, arg);
			}
			return;
		}

		methodName = methodName || {};
		return this.each(function() {
			var cData = $.data(this, "searchinput");
			var opts;
			if (cData) {
				opts = $.extend(cData.options, methodName);
				cData.options = opts;
			} else {
				opts = $.extend(
					{},
					$.fn.searchinput.parseOptions(this), methodName);
			}
			//alert(callback);

			var id = $(this).attr("id");
			var value = $(this).val();
			var showText = opts.text;
			if(typeof(opts.text)=="undefined")
				showText="";
			//alert();
			var html ="<div id='content"+id+"' class='search-content'> <div id='search-first"+id+"' class='search-first'>";
			html = html +"<input class='search-text' id='"+$(this).attr("id")+"' value='"+showText+"' type='text' /> </div>";
			html = html +"<input type='hidden'  id='"+id+"value' name='"+$(this).attr("id")+"' value='"+opts.code+"' />";
			html = html +"<div id='"+$(this).attr("id")+"_append' class='search-append'></div> </div>";
			
			//$(this).replaceWith(html);
			$(this).after(html);
			$(this).remove();
			var obj = $("#"+id);
			//$(obj).val(value);

			$(obj).bind("focus",function (){
				$(obj).bind('input propertychange', function() {
					searchinput(obj,opts);
					tmp_obj_id = $(obj).attr("id");
				});
			});
			
			$(obj).bind("blur",function (){
				$(obj).unbind('input propertychange');
			});

			$("#content"+id).click(function(e){
				$(this).show();
				var id = $(this).attr("id");
				e.stopPropagation();//阻止冒泡$("[href$='.jpg']")
				$("[id$='_append']").each(function(){
					if($(this).attr("id")!=(id+"_append")){
						$(this).hide();
					}
				});
			});
			$(document).click(function(){
				$("#"+$(obj).attr("id")+"_append").hide();
			});
		});
		function searchinput(obj,opts){
			var _search_kw_id='';
			var kw = jQuery.trim($(obj).val());
			_search_kw_id=$(obj).attr("id");
			//$("#vv").val(_search_kw_id);
			if(kw == ""){
				$("#"+_search_kw_id+"_append").hide().html("");
				return false;
			}
			var html = "";
			var url=baseUrl+opts["url"];
			globalShowMask=false;
			var pdata={keyWord:$(obj).val()};
			$.ajax({
				type:'post',
				url:url,
				data:pdata,
				dataType:"text",
				success:function(result)
				{   
					var flag= false ;
					var data=eval('('+result+')');
					for(var i = 0; i < data.length; i++){
						var code = data[i].code;
						var name = data[i].name;
						if (name.indexOf(kw) >= 0) {
							if(kw==name){
								$("#"+$(obj).attr("id")+"value").val(code);
								flag =true ;
							}
							html = html + "<div id='"+_search_kw_id+"_"+code+"' class='item' onmouseenter='getFocus(this)' onClick=\"getCon(this,"+opts["callback"]+");\">" + name + "</div>";
						}
					}
					  if(!flag){
						$("#"+$(obj).attr("id")+"value").val(kw);	
					   }
					$("#"+_search_kw_id+"_append").hide().html("");
					if(html != ""){
						
						$("#"+_search_kw_id+"_append").show().html(html);
					}
				}
			});
			globalShowMask=false;
		}
	}

	$(document).keydown(function(e){
		e = e || window.event;
		var keycode = e.which ? e.which : e.keyCode;
		var _search_kw_id = tmp_obj_id ;
		var appendId=_search_kw_id+"_append";
		if(jQuery.trim($("#"+appendId).html())==""){
			return;
		}
		var appendObj=$("#"+appendId);
		if(keycode == 38){
			//Up Arrow
			$("#"+_search_kw_id).blur();
			var index = appendObj.find(".addbg").prevAll().length;
			if(index == 0){
				appendObj.find(".item").removeClass('addbg').eq(appendObj.find(".item").length-1).addClass('addbg');
			}else{
				appendObj.find(".item").removeClass('addbg').eq(index-1).addClass('addbg');
			}
		}else if(keycode == 40){
			//Dw Arrow
			$("#"+_search_kw_id).blur();
			if(appendObj.find(".item").hasClass("addbg")){
				var index = appendObj.find(".addbg").prevAll().length;
				if(index == appendObj.find(".item").length-1){
					appendObj.find(".item").removeClass('addbg').eq(0).addClass('addbg');
				}else{
					appendObj.find(".item").removeClass('addbg').eq(index+1).addClass('addbg');
				}
			}else{
				appendObj.find(".item").removeClass('addbg').eq(0).addClass('addbg');
			}

		}else if(keycode == 13){
			$("#"+_search_kw_id).blur();
			var value = appendObj.find(".addbg").text();
			//alert($(".addbg").attr("id").split("_")[1]);
			//alert($(".addbg").attr("id").split("_")[0]+"value");
			$("#"+appendObj.find(".addbg").attr("id").split("_")[0]+"value").val(appendObj.find(".addbg").attr("id").split("_")[1]);
			$("#"+_search_kw_id).val(value);
			appendObj.find(".addbg").click();
			$("#"+_search_kw_id+"_append").hide().html("");
		}
	});

	$.fn.searchinput.methods = {
		options : function(jq) {
			return $.data(jq[0], "searchinput").options;
		},getText : function(obj){
			return $(obj).val();
		},
		getValue : function(obj){
			return $("#"+$(obj).attr("id")+"value").val();
		}
	};

	$.fn.searchinput.parseOptions=function(obj){
		return $.extend({},$.fn.panel.parseOptions(obj),$.parser.parseOptions(obj,["url","callback","text","code"]),{});
	};

})(jQuery);
function callback_(callback,name,code){
	if(callback!=undefined){
		if(typeof(callback)=="function")
		{
			var func = new Function();
			func = eval(callback);
			func(name,code);
		}
		else
			eval(callback+"('"+name+"','"+code+"')");
	}
}
function getFocus(obj){
	$(".item").removeClass("addbg");
	$(obj).addClass("addbg");
}
function getCon(obj,callback){
	var value = $(obj).text();
	$("#"+$(obj).attr("id").split("_")[0]).val(value);
	$("#"+$(obj).attr("id").split("_")[0]+"_append").hide().html("");
	$("#"+$(obj).attr("id").split("_")[0]+"value").val($(obj).attr("id").split("_")[1]);
	callback_(callback,value,$(obj).attr("id").split("_")[1]);
}


(function($){

	$.fn.orgtree = function(methodName,arg){
		var defaults = {
			validity:"",
			showtype:"1",
			departtype:"2",
			multiselect:"",
			checkedvalue:"",
			rootid:"-1",
			isreadonly:"",
			onclick:function(){}
		}
		if(typeof methodName == 'string')
		{
			var methodObj = $.fn.orgtree.methods[methodName];
			if(methodObj) {
				return methodObj(this, arg);
			} else {
				return this.hybase(methodName, arg);
			}
		}
		methodName = methodName || {};
		var options = $.extend({},defaults,methodName);

		return this.each(function(){
			options = $.extend({},options,$.fn.orgtree.parseOptions(this),methodName);
			var url = baseUrl+'/depart/doTree.xhtml?departtype='+options.departtype+'&rootid='+options.rootid+"&checked="+options.checkedvalue+"&pid=-1"+"&validity="+options.validity;;
			if($(this).is("input"))
			{
				$(this).combotree({
					url:url,
					multiple:options.multiselect=='1',
					onBeforeExpand:function(node,param){
						$(this).tree('options').url = baseUrl+'/depart/doTree.xhtml?departtype='+options.departtype+'&rootid='+options.rootid+"&checked="+options.checkedvalue+"&pid="+node.id;
					},
					onLoadSuccess:function(node,data)
					{
						
						$("#_easyui_tree_1").addClass("tree-node-selected");
						$(this).tree('expandAll');
						if(options.isreadonly){
							$(this).find('span.tree-checkbox').unbind().click(function(){
								return false;
							});
						}
					}
				});
				$(this).combotree('setValue', {
					id: options.checkedvalue.toLowerCase(),
					text: ''
				});
				if(options.isreadonly){
					$(this).find('span.tree-checkbox').unbind().click(function(){
						return false;
					});
				}
			}else if($(this).is("ul"))
			{
				var onclick = options.onclick;
				var onloadsuccess = options.onloadsuccess;
				$(this).tree({
					url:url,
					checkbox:options.multiselect=='1',
					onBeforeExpand:function(node,param){
						$(this).tree('options').url = baseUrl+'/depart/doTree.xhtml?departtype='+options.departtype+'&rootid='+options.rootid+"&checked="+options.checkedvalue+"&pid="+node.id+"&validity="+options.validity;
					},
					onSelect:function(node){
						if(onclick!=undefined){
							if(typeof(onclick)=="function")
							{
								var func = new Function();
								func = eval(onclick);
								func(node);
							}
							else
								eval(onclick+"(node)");
						}
					},
					onLoadSuccess:function(node,data)
					{
						$("#_easyui_tree_1").addClass("tree-node-selected");
						if(onloadsuccess!=undefined)
						{
							eval("onloadsuccess(node,data)");
						}
						$(this).tree("expand",$(this).tree("getRoots")[0].target);
						if(options.isreadonly){
							$(this).find('span.tree-checkbox').unbind().click(function(){
								return false;
							});
						}
					}
				});

			}
		});//end each

	};
	$.fn.orgtree.methods={
		getvalue:function(obj)
		{
			var values="";
			$($(obj).tree('getChecked')).each(function(){
				values+=$(this)[0].code+",";
			});
			return values;
		}
	};
	$.fn.orgtree.parseOptions=function(obj)
	{
		return $.extend({},$.fn.panel.parseOptions(obj),$.parser.parseOptions(obj,["validity","departtype","multiselect","checkedvalue","rootid","isreadonly","onclick","onloadsuccess"]),{});
	}

	$.fn.wordviewer = function(arg){
		var src = arg.src == undefined ? $(this).attr("src") : arg.src;
		//var a = $(this).replaceWith("<iframe style='width:100%' src='"+baseUrl+"component/edrawoffice/webwordView.jsp?src="+src+"'></iframe>");
	}
	$.fn.exportword = function(methodName,arg)
	{
		//$(this).replaceWith(" <input type='button' class='btn btn-info' onclick='exportword();' value='"+$(this).val()+"' />");
	}
	$.fn.qrcode = function(methodName,arg)
	{
		var defaults = {
			text:"",
			size:"7"
		}
		var options = $.extend({},defaults,methodName,arg);
		return this.each(function(){
			options = $.extend({},options,$.fn.qrcode.parseOptions(this),methodName);
			//$(this).replaceWith("<img src="+baseUrl+"QRCodeServlet?content="+encodeURI(options.text)+"&size="+options.size+"></img>");
		});

	}
	$.fn.qrcode.parseOptions=function(obj)
	{
		return $.extend({},$.fn.panel.parseOptions(obj),$.parser.parseOptions(obj,["text","size"]),{});
	}
	$.fn.exportpdf=function(obj)
	{
		//$(this).replaceWith(" <input type='button' class='btn btn-info' onclick='exportpdf();' value='"+$(this).val()+"' />");
	}
	$.fn.checkcode=function(obj)
	{
		//$(this).replaceWith("<img src="+baseUrl+"checkcode?"+Math.random()+" onclick=$(this).attr('src',baseUrl+'checkcode?'+Math.random()) title='点击刷新验证码'></img>");
	}

	$.fn.departselwin=function(methodName,arg)
	{
		var defaults = {
			value:"点击此处选择...",
			reset:function(){}
		}
		if(typeof methodName == 'string')
		{
			var methodObj = $.fn.departselwin.methods[methodName];
			if(methodObj) {
				return methodObj(this, arg);
			} else {
				return this.hybase(methodName, arg);
			}
		}
		methodName = methodName || {};
		var options = $.extend({},defaults,methodName);
		return this.each(function(){
			options = $.extend({},options,$.fn.orgtree.parseOptions(this),methodName);
			var id = $(this).attr("id");
			$(this).after("<input type='hidden' id='"+id+"' value=''>");
			$(this).bind("click",function(){
				openWinCallback(baseUrl+"component/publicpage/queryuserdept.jsp?type=1&id="+id, '部门选择框', '600px', '380px', true, false,function setvalue(x,b){
				});
			});
			$(this).attr("id",id+"name");
		});
	}
	$.fn.departselwin.methods={
		reset:function(obj)
		{
			$(obj).val("");
			$(obj).prev().val("");
		}
	}
	function loadSelect(select_obj,text){
		var codetable = $(select_obj).attr("codetable");//代码表名称
		var lazyload=$(select_obj).attr("lazyload");
		if(lazyload==undefined) lazyload="0";
		if(codetable) {
			var parentobject = $(select_obj).attr("parentobject");//保存上级代码的对象
			var parentcode = $(select_obj).attr("parentcode");//上级代码
			var parentct = '';
			if(parentobject != undefined)
				parentct = $("#"+parentobject).attr("codetable");
			var pinyin = $(select_obj).attr("pinyin");
			var othername = $(select_obj).attr("othername");
			var otherword = $(select_obj).attr("otherword");
			var editable = $(select_obj).attr("editable");
			var noparent = $(select_obj).attr("noparent");
			var readonly = $(select_obj).attr("readonly");
			var alltext = $(select_obj).attr("alltext");
			pinyin =pinyin == undefined?"":pinyin;
			noparent = noparent == undefined?"":noparent;
			if((pinyin=="") && (editable==undefined || editable==""))
			{
				$(select_obj).combobox({
			    	editable:false
			    });
			}else if(editable=="1")
			{
				$(select_obj).combobox({
			    	editable:true
			    });
			}
			if(!parentcode) {
				parentcode = "";
			}
			if(parentobject) {
			if($("#"+parentobject).attr("type")=="hidden")
			{
				parentcode = $("#"+parentobject).val();
			}else
			{
					var pv = "";
					try{
						pv=$("#"+parentobject).combobox("getValue");
					}catch(e)
					{
						//console.log(e);
					}
				$("#"+parentobject).combobox({
					editable:editable=="1"?true:false,
					onSelect:function(rec){
						$.ajax({
						url:baseUrl+"codetable/codeSelect.xhtml?codetable=" + codetable + "&parentcode=" 
						+ $("#"+parentobject).combobox("getValue")
						+"&noparent="+noparent
						,
							dataType:"json",
							success:function(data)
							{
								try{
									if($.data(select_obj,"combobox")){
										$(select_obj).combobox("clear");
									}
									$(select_obj).combobox('loadData', data);
								}catch(ex){
									console.log(ex);
								}
							}
						});
					}
				});
				$("#"+parentobject).combobox("setValue",pv);
			}
		}
		if(lazyload=='1'){
			var option_str = "<option value=''>请选择</option>";
			$(obj).html("");
			$(option_str).appendTo($(obj));
		}else{
			var url = baseUrl+"codetable/codeSelect.xhtml?codetable=" + codetable + "&parentcode=" + parentcode+"&parentct="+parentct+"&pinyin="+pinyin+"&noparent="+noparent;
			$.ajax({
				url: url,
				type: 'get',
				dataType: 'json',
				async: false,
				success: function(data){
					if(select_obj.id!="")
						$("#" + select_obj.id + " option").length = 0;
					else{
						console.log("缺少id属性");
						return;
					}
					try{
						if($.data(select_obj,"combobox")){
							$(select_obj).combobox("clear");
						}
						$(select_obj).combobox({
							textField:"name",
							valueField:"code"
						});
						if(alltext!=undefined)
						{
							var alltext_obj = {"name":alltext,"code":""};
							data.reverse().push(alltext_obj);
							data = data.reverse();
						}
						$(select_obj).combobox('loadData', data);
						if(text!="")
							$(select_obj).combobox('setValue', text);
						if(othername!=undefined)
						{
							if($("#"+othername).length==0)
								$("<input type='hidden' id='"+othername+"' name='"+othername+"'/>").insertBefore(select_obj);
							$(select_obj).combobox({
								editable:editable=="1"?true:false,
								onSelect:function(rec)
								{
									var text = $(this).combobox('getText');
									if(checkother(text,otherword))//选择其他
									{
										var othervalue=$(this).combobox("getValue");
										$("#"+othername).val(othervalue);
										$(this).combobox({editable:true});
										$(this).attr("editable",true);
										$(this).combobox("setText","请输入：");
									}else
									{//选择非其他
										if($(this).attr("editable")=="true")
										{
											var v=$(this).combobox("getValue");
											$(this).combobox({editable:false});
											$(this).attr("editable",false);
											$(this).combobox("setValue",v);
											$("#"+othername).val("");
										}
									}
								},
								onChange:function(n,o)
								{
									$(this).combobox("setValue",n.replace("请输入：",""));
								}
						    });
						}
//						$(select_obj).combobox({
//							onChange:function(n,o)
//							{
//								//$(this).addClass("validatebox-invalid textbox-prompt");
//							}
//						});
						if(readonly!=undefined)
						{
							$(select_obj).next().find("input[type='text']").css('background-color',"#eee");
						}
						if(text!="")
							$(select_obj).combobox('setValue', text);
					}catch(ex){
						console.log(ex);
					}
				},
				error: function (XMLHttpRequest, textStatus, errorThrown) {
					console.log(errorThrown);
				}
			});
		}
	}
}
	function checkother(text,otherword)
	{
		if(otherword.indexOf(",")>-1)
		{
			var a = otherword.split(',');
			for(var i=0;i<a.length;i++)
			{
				if(text==a[i])
				{
					return true;
					break;
				}
			}
		}else
		{
			return text == otherword;
		}
	}
	$.fn.codeselect = function(methodName,arg)
	{
		var defaults = {
			codetable:"",
			text:"",
			parentobject:"",
			data:"",
			parentcode:"",
			othername:"",
			editable:false
		}
		if(typeof methodName == 'string')
		{
			var methodObj = $.fn.codeselect.methods[methodName];
			if (methodObj) {
				return methodObj(this, arg);
			} else {
				return this.hybase(methodName, arg);
			}
		}
		methodName = methodName || {};
		var options = $.extend({},defaults,methodName);

		return this.each(function(){
			options = $.extend({},options,$.fn.codeselect.parseOptions(this),methodName);
			if(options!=null && options.data!=undefined && options.data!="")
			{
				var jsondata = JSON.parse(options.data);
				for(var a=0;a<jsondata.length;a++)
				{
					$(this).append("<option value="+jsondata[a].key+">"+jsondata[a].value+"</option>");
				}
				return;
			}
			if(options!=null && options.codetable!=undefined & options.codetable!="")
				$(this).attr("codetable",options.codetable);
			if(options!=null && options.parentobject!=undefined & options.parentobject!="")
				$(this).attr("parentobject",options.parentobject);
			if(options!=null && options.parentcode!=undefined & options.parentcode!="")
				$(this).attr("parentcode",options.parentcode);
			if(options!=null && options.pinyin!=undefined & options.pinyin!="")
				$(this).attr("pinyin",options.pinyin);
			if(options!=null && options.othername!=undefined & options.othername!="")
				$(this).attr("othername",options.othername);
			if(options!=null && options.otherword!=undefined & options.otherword!="")
				$(this).attr("otherword",options.otherword);
			if(options!=null && options.editable!=undefined & options.editable!="")
				$(this).attr("editable",options.editable);
			if(options!=null && options.noparent!=undefined & options.noparent!="")
				$(this).attr("noparent",options.noparent);
			loadSelect(this,options.text);
		});
	}
	$.fn.codeselect.methods={
		getValue:function(obj)
		{
			return $(obj).combobox("getValue");
		}
	}
	$.fn.codeselect.parseOptions=function(obj)
	{
		return $.extend({},$.fn.panel.parseOptions(obj),$.parser.parseOptions(obj,["codetable","pleaseselected","text","parentobject","data","othername"]),{});
	}
})(jQuery);
$.fn.h5imgcompress = function()
{
	$(this).after("<img src='' id='preview' alt=''>");
	document.getElementById($(this).attr("id")).addEventListener('change', handleFileSelect, false);
}

function handleFileSelect (evt) {
	var files = evt.target.files;
	for (var i = 0, f; f = files[i]; i++) {
      // Only process image files.
      if (!f.type.match('image.*')) {
        continue;
      }
      var reader = new FileReader();
      // Closure to capture the file information.
      reader.onload = (function(theFile) {
        return function(e) {
          var i = document.getElementById("preview");
          i.src = event.target.result;
          $(i).css('width',$(i).width()/10+'px');
          //$(i).css('height',$(i).height()/10+'px');
          var quality =  50;
          i.src = jic.compress(i,quality).src;
          i.style.display = "block";
        };
      })(f);
      reader.readAsDataURL(f);
    }
  }
var jic = {
        /**
         * Receives an Image Object (can be JPG OR PNG) and returns a new Image Object compressed
         * @param {Image} source_img_obj The source Image Object
         * @param {Integer} quality The output quality of Image Object
         * @return {Image} result_image_obj The compressed Image Object
         */
        compress: function(source_img_obj, quality, output_format){
             var mime_type = "image/jpeg";
             if(output_format!=undefined && output_format=="png"){
                mime_type = "image/png";
             }
             var cvs = document.createElement('canvas');
             //naturalWidth真实图片的宽度
             cvs.width = source_img_obj.naturalWidth;
             cvs.height = source_img_obj.naturalHeight;
             var ctx = cvs.getContext("2d").drawImage(source_img_obj, 0, 0);
             var newImageData = cvs.toDataURL(mime_type, quality/100);
             var result_image_obj = new Image();
             result_image_obj.src = newImageData;
             return result_image_obj;
        }
}
$.fn.swfimgcompress=function(){
	
	$("<div id='divFlash'><a href='https://get.adobe.com/cn/flashplayer' target='_blank'>您未安装flash插件，无法使用【上传】功能，<br>请点击此处下载最新的flash插件，安装完毕请关闭所有浏览器，并重新登录本系统。</a></div>").insertAfter($(this));
	$("<img id='img1' style='display:none;'/>").insertAfter($(this));
	//$(obj).html(" ");
	var action = $(this).attr("action");
	var btnText = $(this).attr("btnText");
	var imgWidth=$(this).attr("imgWidth");
	var imgHeight=$(this).attr("imgHeight");
	if(imgWidth==undefined || imgWidth=="")
		imgWidth = "1000";
	if(imgHeight==undefined || imgHeight=="")
		imgHeight = "1000";
	if(btnText==undefined || btnText=="")
		btnText = "选择图片...";
	var params = {
			serverUrl: action,
			jsFunction: "flashReturn",
			imgWidth:imgWidth,
			imgHeight:imgHeight,
			imgQuality:50,
			btnText:btnText
		}
	swfobject.embedSWF(baseUrl+"component/swfimgcompress/imgZipUpload.swf", "divFlash", "100", "30", "10.0.0", baseUrl+"component/swfimgcompress/expressInstall.swf", params);
	
}
function flashReturn(type, str) {
	if(type == 'error')
	{
		alert(str);
	}
	else if (type == 'complete')
	{
		var img1 = document.getElementById('img1');
		img1.style.display = "block";
		img1.src = str;
	}
}

//部门选择框
function opendept(){
	var ret = window.showModalDialog("../component/publicpage/queryuserdept.jsp?type=1","dialogHeight:300,dialogWidth:400");
	return ret;
}
//导出页面到word文件
function exportword()
{
	var oWD = new ActiveXObject("Word.Application");
	var oDC = oWD.Documents.Add("",0,1);
	var oRange =oDC.Range(0,1);
	var sel = document.body.createTextRange();
	sel.moveToElementText(PrintA);
	sel.select();
	sel.execCommand("Copy");
	oRange.Paste();
	oWD.Application.Visible = true;
	//window.close();
}
function getExportPath() {
	var shell = new ActiveXObject("Shell.Application");
	var folder = shell.BrowseForFolder(0, '请选择存储目录', 0x0040, 0x11);
	var filePath;
	if(folder != null) {
		filePath = folder.Items().Item().Path;
	}
	return filePath;
}
//导出页面到pdf
function exportpdf(){
	var filePath = getExportPath();
	if(filePath != null) {
		try {
			var word = new ActiveXObject("Word.Application");
			var doc = word.Documents.Add("", 0, 1);
			var range = doc.Range(0, 1);
			var sel = document.body.createTextRange();
			try {
				sel.moveToElementText(content);
			} catch (notE) {
				alert(notE);
				alert("导出数据失败，没有数据可以导出。");
				window.close();
				return;
			}
			sel.select();
			sel.execCommand("Copy");
			range.Paste();
			//word.Application.Visible = true;// 控制word窗口是否显示
			doc.saveAs(filePath + "/导出.pdf", 17);// 保存为pdf格式
			alert("导出成功");
		}catch (e) {
			alert("导出数据失败，需要在客户机器安装Microsoft Office Word 2007以上版本，将当前站点加入信任站点，允许在IE中运行ActiveX控件。");
		}
		finally {
			try {word.quit();
				// 关闭word窗口
			}catch (ex) {}
		}
	}
}